package com.framework.workflow.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.framework.common.domain.ResultData;
import com.framework.workflow.model.WfModule;
import com.framework.workflow.params.ModuleParam;
import com.framework.workflow.service.IModuleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author zzg
 */
@RestController
@RequestMapping("/modules")
@Api(tags = "模块流程管理")
public class ModulesController {
    @Autowired
    private IModuleService modulesService;

    @PostMapping("/listPage")
    @ApiOperation(value = "查询列表")
    public ResultData<?> list(@RequestBody ModuleParam param) {
        Page<WfModule> page = Page.of(param.getPageNo(), param.getPageSize());
        IPage<WfModule> list = modulesService.listPage(param, page);
        return ResultData.data(list);
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增模块")
    public ResultData<?> save(@RequestBody WfModule model) throws Exception {
        String id = modulesService.save(model);
        return ResultData.data(id);
    }


    @ApiOperation(value = "发布")
    @GetMapping(value = "/deploy")
    public ResultData<?> deploy(@RequestParam String id) {
        modulesService.deploy(id);
        return ResultData.success();
    }

    @ResponseBody
    @ApiOperation(value = "删除")
    @PostMapping(value = "/del")
    public ResultData<?> delete(@RequestBody String[] ids) {
        modulesService.delete(ids);
        return ResultData.success();
    }
}
